<template>
  <div class="dashboard-editor-container">

    <panel-group :total-data="totalData" @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import { eqsevenDays, sevenDays } from '@/api/activate'

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart
  },
  data() {
    return {
      ChartData: {
        activateLog: {
          expectedData: [],
          xData: []
        },
        equipment: {
          expectedData: [],
          xData: []
        }
      },
      lineChartData: { },
      totalData: {
        logTotal: 0,
        eqTotal: 0
      }
    }
  },
  created() {
    this.getActivateLogCharData()
    this.getEquipmentCharData()
  },
  methods: {
    getActivateLogCharData() {
      sevenDays().then(response => {
        if (response.code === 200) {
          this.ChartData.activateLog.expectedData = response.data.expectedData
          this.ChartData.activateLog.xData = response.data.xData
          this.totalData.logTotal = response.data.totalData
        }
        this.lineChartData = this.ChartData.activateLog
      })
      // this.ChartData.activateLog = {
      //   expectedData: [100, 120, 161, 134, 105, 160, 165],
      //   xData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      // }
    },
    getEquipmentCharData() {
      eqsevenDays().then(response => {
        if (response.code === 200) {
          this.ChartData.equipment.expectedData = response.data.expectedData
          this.ChartData.equipment.xData = response.data.xData
          this.totalData.eqTotal = response.data.totalData
        }
      })
      // this.ChartData.equipment = {
      //   expectedData: [200, 192, 120, 144, 160, 130, 140],
      //   xData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      // }
    },
    handleSetLineChartData(type) {
      this.lineChartData = this.ChartData[type]
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
